package repository.relsys.services;





import repository.relsys.app.*;


import repository.relsys.services.datacentral.*;

import com.hp.hpl.jena.rdf.model.Model;


import thewebsemantic.Bean2RDF;
import thewebsemantic.RDF2Bean;

public class DataModelManager {

	protected DataProvider dataProvider;
	protected Bean2RDF writer;
	protected RDF2Bean reader;
	protected Model dataSource;

	private static class DataModelManagerHolder
	{
		private static final DataModelManager INSTANCE = new DataModelManager();
	}

	public static DataModelManager getInstance()
	{
		return DataModelManagerHolder.INSTANCE;
	}
	
	public DataProvider getDataProvider() 
	{
		if (null == dataProvider) {
			dataProvider = DataProviderFactory.getDataProvider(Settings
					.getInstance().config.jenaConfig.storeType);
		}
		return dataProvider;
	}
	

	public Model getDataModel()
	{
		if (null == dataSource) {
			dataSource = getDataProvider().getData();
		}
		return dataSource;
	}
	
	 
	
	public RDF2Bean getReader() 
	{
		if (null == reader) {
			reader = new RDF2Bean(getDataModel());
		}
		return reader;
	}
	

	public Bean2RDF getWriter() 
	{
		if (null == writer) {
			writer = new Bean2RDF(getDataModel());
		}
		return writer;
	}

	
	public void flush() 
	{
		getDataProvider().updateDataSource(dataSource);
	}
	
	
	
	
}
